package com.tulele.vtool.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tulele.vtool.mapper.BPosterHistoryMapper;
import com.tulele.vtool.model.BPosterHistory;
import com.tulele.vtool.service.BPosterHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 海报生成记录表(BPosterHistory)表服务实现类
 *
 * @author makejava
 * @since 2020-12-01
 */
@Service("bPosterHistoryService")
public class BPosterHistoryServiceImpl implements BPosterHistoryService {
    @Autowired
    private BPosterHistoryMapper bPosterHistoryMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BPosterHistory queryById(Integer id) {
        return this.bPosterHistoryMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<BPosterHistory> queryAllByLimit(int offset, int limit) {
        return this.bPosterHistoryMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param bPosterHistory 实例对象
     * @return 实例对象
     */
    @Override
    public BPosterHistory insert(BPosterHistory bPosterHistory) {
        this.bPosterHistoryMapper.insert(bPosterHistory);
        return bPosterHistory;
    }

    /**
     * 修改数据
     *
     * @param bPosterHistory 实例对象
     * @return 实例对象
     */
    @Override
    public BPosterHistory update(BPosterHistory bPosterHistory) {
        this.bPosterHistoryMapper.update(bPosterHistory);
        return this.queryById(bPosterHistory.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.bPosterHistoryMapper.deleteById(id) > 0;
    }

    /**
     * 查询多条数据
     *
     * @param bPosterHistory 实例对象
     * @return 对象列表
     */
    @Override
    public PageInfo selectAllByLimit(BPosterHistory bPosterHistory) {

        PageHelper.startPage(bPosterHistory.getPageNum(), bPosterHistory.getPageSize());

        bPosterHistory.setStatus(1); //删除状态 0-删除 1-正常
        List<BPosterHistory> bPosterHistoryList = this.bPosterHistoryMapper.queryAll(bPosterHistory);

        return new PageInfo<BPosterHistory>(bPosterHistoryList);

    }

    @Override
    public List<BPosterHistory> getUserPosterHistory(Integer userId, String gzhCode) {
        return bPosterHistoryMapper.queryUserPosterHistory(userId, gzhCode);
    }
}